home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 March
/
CHIP Mart 1997.iso
/
prg
/
CHKIO
/
CHKPORTS.MOD
< prev
next >
Wrap
Text File
|
1996-04-09
|
5KB
|
178 lines
(* ------------------------------------------------------------ *)
(* Title : CheckPorts *)
(* Version : 1.0 *)
(* Author : PhG *)
(* Overview : scan each port *)
(* Future : no *)
(* Notes : very quick & dirty *)
(* Usage : CHKPORT <port [count]> | <free> | <used> *)
(* *)
(* Who When What *)
(* --- -------- ----------------------------------------------- *)
(* PhG 04-08-96 created *)
(* ------------------------------------------------------------ *)
MODULE ChkPorts;
IMPORT SYSTEM;
IMPORT IO;
IMPORT Str;
IMPORT Lib;
(* ------------------------------------------------------------ *)
TYPE
str = ARRAY [0..15] OF CHAR;
CONST
Empty = 0FFFFH;
PROCEDURE PadHex (v : CARDINAL; n : CARDINAL) : str;
CONST
padStr = "0000000000000000"; (* 16 digits *)
VAR
S : str;
R : str;
value : LONGCARD;
ok : BOOLEAN;
delta : CARDINAL;
BEGIN
n := n MOD 16; (* better safe than sorry! *)
value := LONGCARD(v);
Str.CardToStr (value,S,16,ok);
delta := n - Str.Length(S);
Str.Slice (R,padStr,0,delta);
Str.Append (R,S);
RETURN R;
END PadHex;
PROCEDURE ShowIOport (i : CARDINAL; v : CARDINAL);
VAR
S : str;
BEGIN
S := PadHex (i,4);
IO.WrStr ("I/O port $");
IO.WrStr (S);
IF v = Empty THEN
IO.WrStr (" is probably free ($");
ELSE
IO.WrStr (" is probably NOT free ($");
END;
S := PadHex (v,4);
IO.WrStr (S);
IO.WrStr(")");
IO.WrLn;
END ShowIOport;
PROCEDURE Bye (errcode : CARDINAL);
BEGIN
Lib.SetReturnCode(SHORTCARD(errcode));
HALT;
END Bye;
PROCEDURE GetValue (S : str) : CARDINAL;
VAR
value : LONGCARD;
Base : CARDINAL;
ok : BOOLEAN;
BEGIN
IF S[0] = "$" THEN
Str.Delete (S,0,1);
Base := 16;
ELSE
Base := 10;
END;
value := Str.StrToCard(S,Base,ok);
IF ok = FALSE THEN
IO.WrStr("Parameter ");
IO.WrStr(S);
IO.WrStr(" could not be converted to a number!");
Bye(2);
END;
IF value > 0FFFFH THEN
IO.WrStr("Value ");
IO.WrStr(S);
IO.WrStr(" is superior to $FFFF!");
Bye(2);
END;
RETURN CARDINAL(value);
END GetValue;
(* ------------------------------------------------------------ *)
CONST
FirstIOport = 0000H;
LastIOport = 03FFH;
VAR
S : str;
i : CARDINAL;
v : CARDINAL;
argc : CARDINAL;
firstval : CARDINAL;
lastval : CARDINAL;
BEGIN
argc := Lib.ParamCount();
IF (argc < 1) OR (argc > 2) THEN
IO.WrStr("Usage: CHKPORTS <I/O port [count]> | <FREE> | <USED>");
IO.WrLn;
IO.WrStr("Examples: CHKPORTS $2F8");
IO.WrLn;
IO.WrStr(" CHKPORTS $220 16");
IO.WrLn;
IO.WrStr(" CHKPORTS FREE");
IO.WrLn;
IO.WrStr(" CHKPORTS USED");
IO.WrLn;
IO.WrStr("Note: I/O ports are checked in the [$0000..$03FF] range");
Bye(1);
END;
Lib.ParamStr(S,1);
Str.Caps(S);
IF (S = str("FREE")) AND (argc=1) THEN
FOR i := FirstIOport TO LastIOport DO
v := SYSTEM.InW (i);
IF v = Empty THEN
ShowIOport(i,v);
END;
END;
Bye(0);
ELSIF (S = str("USED")) AND (argc=1) THEN
FOR i := FirstIOport TO LastIOport DO
v := SYSTEM.InW (i);
IF v <> Empty THEN
ShowIOport(i,v);
END;
END;
Bye(0);
END;
firstval := GetValue(S);
IF (firstval < FirstIOport) OR (firstval > LastIOport) THEN
IO.WrStr("I/O port address is not in [$0000..$03FF] range!");
Bye(3);
END;
IF argc=1 THEN
lastval := firstval
ELSE
Lib.ParamStr(S,2);
Str.Caps(S);
lastval := firstval + GetValue(S) -1;
IF (firstval < FirstIOport) OR (firstval > LastIOport) THEN
IO.WrStr("Last I/O port address to check is not in [$0000..$03FF] range!");
Bye(3);
END;
IF lastval < firstval THEN
IO.WrStr("Tsk tsk!");
Bye(3);
END;
END;
FOR i := firstval TO lastval DO
v := SYSTEM.InW (i);
ShowIOport(i,v);
END;
Bye(0);
END ChkPorts.